package leetcode.median;

import leetcode.base.TreeNode;

/**
 * ClassName: $437_PathSum
 * Description:
 * date: 2022-02-19 10:22
 *
 * @author liyifan
 */
public class $437_PathSum {
    public int pathSum(TreeNode root, int targetSum) {
        if (root == null)
            return 0;
        int res = 0;
        res = dfs(root, targetSum);
        res += pathSum(root.left, targetSum);
        res += pathSum(root.right, targetSum);

        return res;
    }

    public int dfs(TreeNode root, int target){
        int res = 0;
        if (root == null) {
            return 0;
        }
        if (root.val == target) {
            res ++;
        }
        res += dfs(root.left, target - root.val);
        res += dfs(root.right, target - root.val);
        return res;
    }
}
